package com.jdzu.common.exception;


import com.jdzu.model.vo.common.Result;
import com.jdzu.model.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice//所有RestController的异常都会被这个方法处理
public class GlobalExceptionHandler {

    @ExceptionHandler(value = GuiguException.class)     // 处理自定义异常
    public Result guiguExceptionHandler(GuiguException exception) {
        exception.printStackTrace();
        return Result.build(null , exception.getResultCodeEnum()) ;
    }

    @ExceptionHandler(value = Exception.class)          // 处理系统异常
    public Result systemExceptionHandler(Exception exception) {
        exception.printStackTrace();
        return Result.build(null , ResultCodeEnum.LOGIN_ERROR) ;
    }

}

